#pragma once
#include "boost/asio.hpp"
#include "Singleton.h"
#include <vector>
#include <memory>
#include <thread>


class AsioIOServicePool:public Singleton<AsioIOServicePool>
{
    using Work = boost::asio::io_context::work;
    using WorkPtr = std::unique_ptr<Work>;
    friend class Singleton<AsioIOServicePool>;
public:
    ~AsioIOServicePool();
    boost::asio::io_context& GetIOService();

    void Stop();

private:
    AsioIOServicePool(std::size_t threadNum=4);
private:
    std::vector<boost::asio::io_context> io_contexts_;
    std::vector<WorkPtr> works_;
    std::vector<std::thread> threads_;
    std::size_t nextIOService_;
};
